﻿Imports System.ComponentModel.Composition

<MetadataAttribute(), AttributeUsage(AttributeTargets.Class, AllowMultiple:=False)>
Public Class ExportCompentAttribute
    Inherits ExportAttribute
    Implements IExtensionCompentMetadata, IEquatable(Of IExtensionCompentMetadata)

    Private _ID As String
    Private _Name As String
    Private _Version As String

#Region "构造函数"

    Public Sub New(contractType As Type, Optional name As String = "Not Named", Optional id As String = "00000000-0000-0000-0000-000000000000", Optional version As String = "1.0.0.0")
        MyBase.New(contractType)
        _Name = name
        _ID = id
        _Version = version
    End Sub
#End Region

    Public ReadOnly Property ID As String Implements IExtensionCompentMetadata.ID
        Get
            Return _ID
        End Get
    End Property

    Public ReadOnly Property Name As String Implements IExtensionCompentMetadata.Name
        Get
            Return _Name
        End Get
    End Property

    Public ReadOnly Property Version As String Implements IExtensionCompentMetadata.Version
        Get
            Return _Version
        End Get
    End Property

    Public Overloads Function Equals(other As IExtensionCompentMetadata) As Boolean Implements System.IEquatable(Of IExtensionCompentMetadata).Equals
        Return Name = other.Name AndAlso ID = other.ID AndAlso Version = other.Version
    End Function

    Public Overrides Function Equals(obj As Object) As Boolean
        If Not TypeOf obj Is ExportCompentAttribute Then Return False
        Return Equals(CType(obj, ExportCompentAttribute))
    End Function

    Public Overrides Function GetHashCode() As Integer
        Return String.Format("{0}&{1}&{2}", Name, ID, Version).GetHashCode
    End Function

    Public Overrides Function Match(obj As Object) As Boolean
        Return Equals(obj)
    End Function

    Public Overrides Function ToString() As String
        Return String.Format("{0}&{1}&{2}", Name, ID, Version)
    End Function

    Public Overrides Function IsDefaultAttribute() As Boolean
        Return Name = "Not Named" AndAlso ID = "00000000-0000-0000-0000-000000000000" AndAlso Version = "1.0.0.0"
    End Function
End Class
